function x = ReverseFeatures(f, num_tilings, num_tiles, tile_width)    
    
    pos = f(1);
    start = (pos-1)*tile_width;
    finish = pos*tile_width;

    for i = 2:num_tilings, 
        old_tilings = 1*num_tiles + (i-2)*(num_tiles+1); % number of tiles in the previous tilings
        offset = ((i-1)/num_tilings)*tile_width; % offset from the first tile
        
        new_pos = f(i);
        
        if(new_pos == old_tilings + 1)
            start_new = 0;
            finish_new = offset;
        elseif(new_pos == old_tilings + 2)
            start_new = offset;
            finish_new = start_new + tile_width;
        else
            start_new = offset + (new_pos - old_tilings - 2)*4;
            finish_new = start_new + tile_width;
        end
        
        if (start_new > start)
            start = start_new;
        elseif (finish_new < finish)
            finish = finish_new;
        end
    end
    
    x = (finish+start)/2;

end